package com.sgb.contract.api;

import com.sgb.contract.base.ContractSdk;
import com.sgb.contract.utils.Constants;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.util.MToast;

import retrofit2.Call;

/**
 * 重写ICallBack实现合同module自己的网络失败处理
 * 合同module所有的网络回调应该使用此类
 * @author cyj
 */
public abstract class AbstractCallBack<T> extends ICallBack<T> {

    @Override
    public void onFailure(Call call, Throwable t) {
        // 拦截底层实现，因为底层逻辑不适合在线合同业务逻辑
    }

    @Override
    final public void onFailureWithEntity(BaseEntity entity) {
        // self.customErrorCode = @[@(539101), @(539102), @(539103), @(539104), @(539105), @(539106), @(539114)];
        if(Constants.NET_BSS_ERROR_CODE_539101.equals(entity.getErrCode())
            || Constants.NET_BSS_ERROR_CODE_539102.equals(entity.getErrCode())
            || Constants.NET_BSS_ERROR_CODE_539103.equals(entity.getErrCode())
            || Constants.NET_BSS_ERROR_CODE_539104.equals(entity.getErrCode())
            || Constants.NET_BSS_ERROR_CODE_539105.equals(entity.getErrCode())
            || Constants.NET_BSS_ERROR_CODE_539114.equals(entity.getErrCode())
            || Constants.NET_BSS_ERROR_CODE_539106.equals(entity.getErrCode())) {
            onBusinessFailure(entity);
        } else {

            MToast.showToast(ContractSdk.getApplication(), entity.getMsg() + "");
        }
    }

    /**
     * 业务失败回调
     * 相关的在线合同-业务-需要使用弹窗的业务错误码 {@link com.sgb.contract.utils.Constants}
     * @param entity
     */
    public void onBusinessFailure(BaseEntity entity) {

    }

}
